Skip to contentSkip to conversation

Change in openvpn[release/2.6]: buffer: use memcpy in buf_catrunc

Openvpn-devel In review flichtenheld (Code Review) 3 participants 8 messages Jul 21, 2023 – Sep 23, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1689947729000.If4a67adac4d2e870fd719b58075d39efcd67c671@...2715...

#1 lore raw

flichtenheld has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=email )

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

buffer: use memcpy in buf_catrunc

Since we use strlen() to determine the length
and then check it ourselves, there is really
no point in using strncpy.

But the compiler might complain that we use
the output of strlen() for the length of
strncpy which is usually a sign for bugs:

error: ‘strncpy’ specified bound depends
on the length of the source argument
[-Werror=stringop-overflow=]

Warning was at least triggered for
mingw-gcc version 10-win32 20220113.

Also change the type of len to size_t
which avoids potential problems with
signed overflow.

v2:
- make len size_t and change code to avoid any theoretical overflows
- remove useless casts
v3:
- fix off-by-one introduced by v2 %)
v4:
- ignore unsigned overflow to simplify code

Change-Id If4a67adac4d2e870fd719b58075d39efcd67c671
(cherry picked from commit c89a97e449baaf60924a362555d35184f188a646)

---
M src/openvpn/buffer.c

1 file changed, 2 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/14/314/1

src/openvpn/buffer.c +2 -2
index d099795..7725438 100644
@@ -316,10 +316,10 @@
 {
     if (buf_forward_capacity(buf) <= 1)
     {
-        int len = (int) strlen(str) + 1;
+        size_t len = strlen(str) + 1;
         if (len < buf_forward_capacity_total(buf))
         {
-            strncpynt((char *)(buf->data + buf->capacity - len), str, len);
+            memcpy(buf->data + buf->capacity - len, str, len);
         }
     }
 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=email )

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 15 Aug 2023 23:22:04 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

d12fk has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=email )

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 18 Sep 2023 20:15:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#4 lore raw

PATCH 1/1 buffer: use memcpy in buf_catrunc

In reply to a message not in the archive

Since we use strlen() to determine the length and then check it ourselves, there is really no point in using strncpy.

But the compiler might complain that we use the output of strlen() for the length of strncpy which is usually a sign for bugs:

error: ‘strncpy’ specified bound depends
on the length of the source argument [-Werror=stringop-overflow=]

Warning was at least triggered for
mingw-gcc version 10-win32 20220113.

Also change the type of len to size_t
which avoids potential problems with
signed overflow.

v2:
- make len size_t and change code to avoid any theoretical overflows
- remove useless casts
v3:
- fix off-by-one introduced by v2 %)
v4:
- ignore unsigned overflow to simplify code

Change-Id If4a67adac4d2e870fd719b58075d39efcd67c671
(cherry picked from commit c89a97e449baaf60924a362555d35184f188a646)

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to release/2.6.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/314
This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above):
Antonio Quartulli <[email protected]...>
Heiko Hund <[email protected]...>

src/openvpn/buffer.c +2 -2
index d099795..7725438 100644
@@ -316,10 +316,10 @@
 {
     if (buf_forward_capacity(buf) <= 1)
     {
-        int len = (int) strlen(str) + 1;
+        size_t len = strlen(str) + 1;
         if (len < buf_forward_capacity_total(buf))
         {
-            strncpynt((char *)(buf->data + buf->capacity - len), str, len);
+            memcpy(buf->data + buf->capacity - len, str, len);
         }
     }
 }
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: buffer: use memcpy in buf_catrunc

Straightforward cherrypick, smoke tested on linux.

Your patch has been applied to the release/2.6 branch.

commit 946219115d00c6ae658afcf538249e721e6bd600 (release/2.6)

Author: Frank Lichtenheld
Date:   Fri Sep 22 18:04:41 2023 +0200
     buffer: use memcpy in buf_catrunc

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Acked-by: Heiko Hund <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg27085.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld.

Hello cron2, d12fk, ordex,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/314?usp=email

to look at the new patch set (#2).

The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

buffer: use memcpy in buf_catrunc

Since we use strlen() to determine the length
and then check it ourselves, there is really
no point in using strncpy.

But the compiler might complain that we use
the output of strlen() for the length of
strncpy which is usually a sign for bugs:

error: ‘strncpy’ specified bound depends
on the length of the source argument
[-Werror=stringop-overflow=]

Warning was at least triggered for
mingw-gcc version 10-win32 20220113.

Also change the type of len to size_t
which avoids potential problems with
signed overflow.

v2:
- make len size_t and change code to avoid any theoretical overflows
- remove useless casts
v3:
- fix off-by-one introduced by v2 %)
v4:
- ignore unsigned overflow to simplify code

Change-Id If4a67adac4d2e870fd719b58075d39efcd67c671
(cherry picked from commit c89a97e449baaf60924a362555d35184f188a646)

---
M src/openvpn/buffer.c

1 file changed, 2 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/14/314/2

src/openvpn/buffer.c +2 -2
index d099795..7725438 100644
@@ -316,10 +316,10 @@
 {
     if (buf_forward_capacity(buf) <= 1)
     {
-        int len = (int) strlen(str) + 1;
+        size_t len = strlen(str) + 1;
         if (len < buf_forward_capacity_total(buf))
         {
-            strncpynt((char *)(buf->data + buf->capacity - len), str, len);
+            memcpy(buf->data + buf->capacity - len, str, len);
         }
     }
 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#3) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by d12fk, Code-Review+2 by ordex

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

buffer: use memcpy in buf_catrunc

Since we use strlen() to determine the length and then check it ourselves, there is really no point in using strncpy.

But the compiler might complain that we use the output of strlen() for the length of strncpy which is usually a sign for bugs:

error: ‘strncpy’ specified bound depends
on the length of the source argument [-Werror=stringop-overflow=]

Warning was at least triggered for
mingw-gcc version 10-win32 20220113.

Also change the type of len to size_t
which avoids potential problems with
signed overflow.

v2:
- make len size_t and change code to avoid any theoretical overflows
- remove useless casts
v3:
- fix off-by-one introduced by v2 %)
v4:
- ignore unsigned overflow to simplify code

Change-Id If4a67adac4d2e870fd719b58075d39efcd67c671
(cherry picked from commit c89a97e449baaf60924a362555d35184f188a646)

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27085.html

---
M src/openvpn/buffer.c

1 file changed, 2 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/14/314/3

src/openvpn/buffer.c +2 -2
index d099795..7725438 100644
@@ -316,10 +316,10 @@
 {
     if (buf_forward_capacity(buf) <= 1)
     {
-        int len = (int) strlen(str) + 1;
+        size_t len = strlen(str) + 1;
         if (len < buf_forward_capacity_total(buf))
         {
-            strncpynt((char *)(buf->data + buf->capacity - len), str, len);
+            memcpy(buf->data + buf->capacity - len, str, len);
         }
     }
 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#8 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=email )

Change subject: buffer: use memcpy in buf_catrunc
......................................................................

buffer: use memcpy in buf_catrunc

Since we use strlen() to determine the length and then check it ourselves, there is really no point in using strncpy.

But the compiler might complain that we use the output of strlen() for the length of strncpy which is usually a sign for bugs:

error: ‘strncpy’ specified bound depends
on the length of the source argument [-Werror=stringop-overflow=]

Warning was at least triggered for
mingw-gcc version 10-win32 20220113.

Also change the type of len to size_t
which avoids potential problems with
signed overflow.

v2:
- make len size_t and change code to avoid any theoretical overflows
- remove useless casts
v3:
- fix off-by-one introduced by v2 %)
v4:
- ignore unsigned overflow to simplify code

Change-Id If4a67adac4d2e870fd719b58075d39efcd67c671
(cherry picked from commit c89a97e449baaf60924a362555d35184f188a646)

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27085.html

---
M src/openvpn/buffer.c

1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/buffer.c +2 -2
index d099795..7725438 100644
@@ -316,10 +316,10 @@
 {
     if (buf_forward_capacity(buf) <= 1)
     {
-        int len = (int) strlen(str) + 1;
+        size_t len = strlen(str) + 1;
         if (len < buf_forward_capacity_total(buf))
         {
-            strncpynt((char *)(buf->data + buf->capacity - len), str, len);
+            memcpy(buf->data + buf->capacity - len, str, len);
         }
     }
 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: d12fk <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged